package com.itheima.tliasmanager.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tliasmanager.mapper.ClazzMapper;
import com.itheima.tliasmanager.pojo.domain.Clazz;
import com.itheima.tliasmanager.pojo.dto.ClazzQueryParam;
import com.itheima.tliasmanager.pojo.vo.PageResult;
import com.itheima.tliasmanager.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ClazzServiceImpl implements ClazzService {

    @Autowired
    private ClazzMapper clazzMapper;


    @Override
    public PageResult<Clazz> page(ClazzQueryParam queryParam) {
        //1.
        PageHelper.startPage(queryParam.getPage(),queryParam.getPageSize());

        //2.
        Page<Clazz> page = (Page<Clazz>) clazzMapper.selectByCondition(queryParam);

        //3.封装分页查询结果数据
        page.getResult().stream().forEach(c->c.panDuan());

        return new PageResult<>(page.getTotal(),page.getResult());
    }

}
